# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   selenium_self
# FileName:      sign_type_page.py
# Author:       test_liu
# Datetime:     2024/8/15 下午6:29
# Description: 竞赛类型
# ---------------------------------------------------------------------------
import time

from WebTest1.common.read_ini import ReadIni
from WebTest1.page.login_page import Login

from WebTest1.common.simple import SE


# 登录设置默认('123', '123')
class SignType(Login):
    def __init__(self,  web='e', username='123', password='123'):
        super().__init__(web=web)
        # 登录
        self.login(username=username, password=password)
        self.se = SE()
        # 获取截图目录
        ini = ReadIni()
        self.screen_path = ini.get_file_path("img")
        # 进入竞赛类型设置页面
        self.se.xpath_click(self.driver, '//*[text()="竞赛类型设置"]').click()

    def add_sign(self, type):
        self.se.xpath_click(self.driver, '//*[text()="新增"]').click()
        self.se.css_element(self.driver, 'form > div > div > div > input').send_keys(type)
        # 取消0 确定1
        button_click = self.se.css_elements(self.driver, 'div.dialog-footer > button')
        button_click[1].click()
        time.sleep(0.09)
        res = self.se.css_elements(self.driver, '[class="el-message__content"]')[-1].text
        print(res)
        if res != '保存成功':
            # 点击取消，返回竞赛类型设置页面
            button_click[0].click()
        return res

    # 编辑第i个元素(从0开始)
    def update_sign(self, i=0):
        self.se.xpath_elements(self.driver, '//*[text()="编辑"]')[i].click()
        time.sleep(10)

    def delete_sign(self):
        pass

    # 截图
    def save_screen(self, id, *args):
        time.sleep(0.1)
        self.driver.get_screenshot_as_file(f"{self.screen_path}/signType_{id}.png")


if __name__ == '__main__':
    sign = SignType()
    sign.add_sign(type='123')

